package backend.model.other;

import backend.model.admin.Project;
import backend.model.base.DBModel;
import org.hibernate.annotations.NamedQueries;
import org.hibernate.annotations.NamedQuery;
import shared.other.MonthStateEnum;

import javax.persistence.*;

@NamedQueries({@NamedQuery(name = "findMonthStateByMonthAndYear", query = "from MonthState where month = :month and year = :year")
})

@Entity
@Table(name = "month_state")
public class MonthState extends DBModel {

    @Id
    @GeneratedValue
    @Column(name = "id")
    private int id;

    @Column(name = "month")
    private int month;

    @Column(name = "year")
    private int year;

    @Column(name="state")
    @Enumerated(EnumType.ORDINAL)
    private MonthStateEnum state;

    @Override
    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public int getMonth() {
        return month;
    }

    public void setMonth(int month) {
        this.month = month;
    }

    public int getYear() {
        return year;
    }

    public void setYear(int year) {
        this.year = year;
    }

    public MonthStateEnum getState() {
        return state;
    }

    public void setState(MonthStateEnum state) {
        this.state = state;
    }

    @Override
    public String getDisplayLabel() {
        return "Year: " + year + ", Month: " + month + ", State: " + state.getDisplayValue();
    }

    @Override
    public boolean getIsActive() {
        return true;
    }

    @Override
    public int compareTo(Object o) {
        if (!(o instanceof MonthState)) {
            return -1;
        } else {
            Project otherProject = (Project) o;
            return getDisplayLabel().compareTo(otherProject.getDisplayLabel());
        }
    }
}
